<div class="container">
	<div style="padding-top: 25px">
		<form class="form-horizontal" method="post" id="inputForm"
			novalidate="novalidate">
			<div class="form-group">
				<label class="col-sm-2 control-label" for="checkin_title">适用终端:</label>
				<div class="col-sm-10 childblock" id="iosForm" style="display: none">
					<!-- 
					<label> <span style="line-height: 40px"><input type="radio" checked="checked"
						value="iphone" name="iosfixWidget" class="choice">iphone</span>
					</label> 
					
					<label> <span style="line-height: 40px"><input
							type="radio" value="ipad" name="iosfixWidget" class="choice">ipad</span>
					</label>
					 -->
					<label><span style="line-height: 40px"><input
							type="radio" value="all" name="iosfixWidget" checked="checked">iphone&ipad
					</span> </label>

				</div>
				<div class="col-sm-10 childblock" id="androidForm"
					style="display: none">
					<label> <span style="line-height: 40px"><input
							type="radio" checked="checked" value="android"
							name="androidfixWidget" class="choice">android</span>
					</label>
					<!--  
					<label> <span style="line-height: 40px"><input type="radio" value="pad"
						name="androidfixWidget" class="choice">pad
						</span>
					</label> <label><span style="line-height: 40px"> <input type="radio" value="all"
						name="androidfixWidget" class="choice">android&pad</span>
					</label>
					-->
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-2 control-label">证书配置:</label> <span
					class="btn-info btn-sm" id="infosecret" style="line-height: 40px"
					onclick="uploadCert()">未配置</span> <input type="hidden"
					name="secret" value="{{secret}}" id="secretHidden">
			</div>
			<div class="form-group">
				<div class="col-sm-offset-2 col-sm-10">
					<input type="button" value="打包" class=" btn btn-primary tls"
						onclick="formSubmit()"> <input type="button" value="返回"
						onclick="back()" class="btn btn-primary tls">
				</div>
			</div>
		</form>
	</div>
</div>

<script type="text/javascript">
	var appId = '{{appId}}';
	var version = '{{version}}';
	var platform = '{{platform}}';
	var build = $('#buildInput').val();
	var release_note = $('#release_note').val();
	var secret = '{{secret}}';
	if (secret != "") {
		$('#infosecret').text("已配置");
	}

	if (platform === "android") {
		$('#androidForm').show();
		$('#iosForm').remove();
	} else if (platform === "ios") {
		$('#iosForm').show();
		$('#androidForm').remove();
	}

	//打开证书配置对话框
	function uploadCert() {
		var op = {
			remote : "{{ctx}}/mam/secret/" + platform + "?appId=" + appId,
			show : true
		};
		$('#btn_modal').unbind();
		$('#btn_modal').bind("click", function() {
			secretSubmit();
		});
		$('#myModal').modal(op);

	}

	function formSubmit() {
		if (platform === "ios") {
			var secretHidden = $('#secretHidden').val();
			console.log(secretHidden);
			if (secretHidden != "") {
				packrequest();
			} else {
				bootbox.alert("您还没有配置证书，请先进行配置！");
			}
		} else {
			packrequest();
		}

	}

	function back() {
		$('#panel-3_active').click();
	}
	//请求打包接口
	function packrequest() {
		var obj = {};
		obj.appId = appId;
		obj.version = version;
		obj.platform = platform;
		obj.build = build;
		obj.release_note = release_note;
		$.ajax({
			async : true,
			type : "POST",
			url : "{{ctx}}/mam/pkg/package",
			data : JSON.stringify(obj),
			dataType : 'json',
			contentType : 'application/json',
			success : function(data, textStatus) {
				if (data.result == "success") {
					$('#packageSeq').val(data.task_id);
					$('#status').val("2");
					var loadImage = $("<img>").attr("src",
							"{{ctx}}/static/bsl/images/loadImage.gif").attr(
							"style", "width: 20px; height: 20px;");
					$("#statusinfo").empty();
					$("#statusinfo").append("正在打包...");
					$("#statusinfo").append(loadImage);
					$('#lisapn').text("打包中");
					var atag = $('#packageSeq').parent().find('a');
					$(atag).each(function(index) {
						$(this).attr("disabled", "disabled");
					});
					$("#btn-primarySubmit").attr("disabled", "disabled");
					$('#panel-1_active').click();
					reloadInterval();
				} else {
					bootbox.alert("系统繁忙，请稍后再试！");
				}
			},
			error : function(data, status, e) {
				bootbox.alert("系统繁忙，请稍后再试！");
			}
		});
	}
</script>